package com.pay.order.controller;

import com.pay.common.result.Result;
import com.pay.order.dto.OrderCreateRequest;
import com.pay.order.dto.OrderCreateResponse;
import com.pay.order.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;

@Slf4j
@RestController
@RequestMapping("/api/order")
public class OrderController {
    
    @Autowired
    private OrderService orderService;
    
    /**
     * 创建订单
     */
    @PostMapping("/create")
    public Result<OrderCreateResponse> createOrder(@RequestBody OrderCreateRequest request) {
        log.info("创建订单请求：{}", request);
        return orderService.createOrder(request);
    }
    
    /**
     * 查询订单
     */
    @GetMapping("/{orderNo}")
    public Result<OrderCreateResponse> getOrder(@PathVariable String orderNo) {
        log.info("查询订单请求：{}", orderNo);
        return orderService.getOrder(orderNo);
    }
    
    /**
     * 取消订单
     */
    @PostMapping("/{orderNo}/cancel")
    public Result<Void> cancelOrder(@PathVariable String orderNo) {
        log.info("取消订单请求：{}", orderNo);
        return orderService.cancelOrder(orderNo);
    }
    
    /**
     * 测试创建订单（简化版）
     */
    @PostMapping("/test/create")
    public Result<OrderCreateResponse> testCreateOrder() {
        OrderCreateRequest request = new OrderCreateRequest();
        request.setMerchantId("TEST_MERCHANT_001");
        request.setProductId("PROD_001");
        request.setAmount(new BigDecimal("100.00"));
        request.setCurrency("CNY");
        request.setDescription("测试订单");
        request.setNotifyUrl("http://localhost:8081/api/notify");
        request.setReturnUrl("http://localhost:8081/api/return");
        
        log.info("测试创建订单请求：{}", request);
        return orderService.createOrder(request);
    }
}



